﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.Linq;
using QLKetNoi;

namespace QLDVu.BO
{
    class DanhSachXeBO
    {
       
        public static Table<XE> DanhSachXe()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<XE>();

        }
        //public static XE XeCuoiCung()
        //{
        //    QuanLyGaraDataContext dulieu = new QuanLyGaraDataContext();
        //    XE s = dulieu.XEs.OrderByDescending(hh => hh.MaXe).FirstOrDefault();
        //    return s;

        //}
        public static XE DanhSachXe(string biensoxe)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<XE> xe= dulieu.GetTable<XE>();
            XE x = xe.Single(xx => xx.BienSoXe.Equals(biensoxe));
            return x;

        }
        public static Table<DOIXE> DanhSachDoiXe()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<DOIXE>();

        }
        public static Table<HANGSX> DanhSachHangSanXuat()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<HANGSX>();

        }
        public static Table<DONGXE> DanhSachDongXe()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<DONGXE>();

        }
        public static IEnumerable<DONGXE> DanhSachDongXeTheoHangSanXuat(string masanxuat)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<DONGXE> dongxe = dulieu.GetTable<DONGXE>();
            IEnumerable<DONGXE> dx = from dxe in dongxe
                                     where dxe.MaHangSanXuat.Equals(masanxuat)
                                     select dxe;
            return dx;

        }
        public static IEnumerable<DOIXE> DanhSachDoiXeTheoDongXe(string madongxe)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<DOIXE> dongxe = dulieu.GetTable<DOIXE>();
            IEnumerable<DOIXE> dx = from dxe in dongxe
                                     where dxe.MaDongXe.Equals(madongxe)
                                     select dxe;
            return dx;

        }
        public static void ThemXe(string biensoxe,string sosuon,string madongxe,string mahangsanxuat,string madoixe)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<XE> xe = dulieu.GetTable<XE>();
            XE x = new XE();
            x.BienSoXe = biensoxe;
            
            x.SoSuon = sosuon;
            x.MaHangSanXuat = mahangsanxuat;
            x.MaDoiXe = madoixe;
            x.MaDongXe = madongxe;
            xe.InsertOnSubmit(x);
            dulieu.SubmitChanges();

        }
    }
}
